<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件嵌套</title>
    <script src="/js/vue-2.7.9-dev.js"></script>
</head>
<body>
    <div id="app">
        <!-- 3.使用组件 -->
        <school></school>
    </div>

    <script>
        // 1.定义组件
        let stu = Vue.extend({
            data() {
                return {
                    name:"张三",
                    age:"18"
                }
            },
            methods: {
                showName(){
                    console.log("stu 的this", this);
                    alert(this.name)
                }
            },
            template:'<div><h3>学生姓名 {{name}}</h3><h6>学生年龄{{age}}</h6><button @click="showName">显示名字</button>  </div>'
        })
        console.log("stu", stu);

        let school = {
            data() {
                return {
                    name:"山西晋中理工",
                }
            },
            template:'<div><h3>学校名称 {{name}}</h3><my-Stu></my-Stu> </div> ',
        }
        // 全局注册组件
        Vue.component("school", school)
        Vue.component("MyStu",stu)

        let vm = new Vue({
            data() { 
                console.log("==", this);
                return { 
                }
            },
        })
        vm.$mount("#app")
        console.log("--",vm);
    </script>
</body>
</html>